package br.com.dataphonebr.adapter;

import java.util.List;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import br.com.dataphonebr.R;
import br.com.dataphonebr.entity.Usuario;
import br.com.dataphonebr.service.GenericAdapterService;

public class UserAdapter extends GenericAdapterService<Usuario> {
	
	public UserAdapter(List<Usuario> list) {
		super(list);
	}

	LayoutInflater inflater;
	
	@Override
	public View getView(int index, View view, ViewGroup parent) {
		
		View newView = super.getView(index, view, parent, R.layout.item_user_row);
		Usuario usuario = getList().get(index);
		if (usuario == null)
			usuario = new Usuario();
		
		TextView nameTextView = getTextView(R.id.txtUserName, newView);
		nameTextView.setText(usuario.getNome());

		TextView emailTextView = getTextView(R.id.txtEmail, newView);
		emailTextView.setText(usuario.getEmail());

		TextView loginTextView = getTextView(R.id.txtLogin, newView);
		loginTextView.setText(usuario.getLogin());

		if (!usuario.getEnabled()){
			loginTextView.setText(usuario.getLogin()+" (inativo)");
			nameTextView.setTextColor(Color.LTGRAY);
			emailTextView.setTextColor(Color.LTGRAY);
			loginTextView.setTextColor(Color.LTGRAY);
		} else {
			nameTextView.setTextColor(Color.BLACK);
			emailTextView.setTextColor(Color.BLACK);
			loginTextView.setTextColor(Color.BLACK);
		}
		
		return newView;
	}

	@Override
	protected Usuario cursorToEntity() {
		return null;
	}

}
